<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.7.1.min.js"></script>
<!--<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="--><?php //echo URL::base() ?><!--media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>-->
<script src="<?php echo URL::base() ?>media/laydate/laydate.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.core.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.widget.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.position.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.autocomplete.min.js"></script>
<div class="container-fluid">
    <form class="form-horizontal" method='get' action='<?php echo URL::site() ?>stock/index'>
        <?php
        $date_from = isset($_GET['date_from']) && trim($_GET['date_from']) ? date('Y-m-d', strtotime($_GET['date_from'])) : '';
        $date_to = isset($_GET['date_to']) && trim($_GET['date_to']) ? date('Y-m-d', strtotime($_GET['date_to'])) : '';
        $sku = isset($_GET['sku']) ? htmlspecialchars($_GET['sku']) : '';
        $supplier_name = isset($_GET['supplier_name']) ? htmlspecialchars($_GET['supplier_name']) : '';
        ?>
        <div class="control-group">
            <label class="control-label">SKU:</label>
            <div class="controls">
                <input type="text" class="input-xlarge" name="sku" id="sku" value="<?php echo $sku; ?>">
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">供应商名称:</label>
            <div class="controls">
                <!--<input type="text" class="input-mini" name="supplier_id" id="supplier_id" value="" autocomplete="off" readonly>-->
                <input name="supplier_name" class="input-xlarge" id="supplier_name" value="<?php echo $supplier_name; ?>"
                       autocomplete="off"  type="text"/>
                <!--<a href="javascript:clear();" class="btn">重选</a>-->
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">起止时间:</label>
            <div class="controls">
                <input  class="input-medium datepicker" type="text" value="<?php echo $date_from; ?>" name='date_from' id="date_from"/>
                到 <input class="input-medium datepicker" type="text" value="<?php echo $date_to; ?>" name='date_to' id="date_to"/>
            </div>
        </div>
        <div class="control-group">
            <div class="controls">
                <input class="btn btn-info" type="submit" name="sub" value="查询" onclick="javascript:$('input[name=\'act\']').val('query')"/>
                <input class="btn" type="submit" name="downbtn" id="downbtn" value="导出" onclick="javascript:$('input[name=\'act\']').val('export')"/>
                <input type="hidden" name="act" value="query" />
            </div>
        </div>
    </form>
    <table class="table table-hover">
        <thead>
        <tr>
            <th>供应商</th>
            <th>SKU</th>
            <th>中文名称</th>
            <th>单位</th>
            <th>仓库</th>
            <!--<th>储位</th>-->
            <th>当前库存量</th>
            <th><?php echo $days; ?>销量</th>
        </tr>
        </thead>
        <?php 
        foreach ($data['stocks'] as $k=>$v){
            $product = $data['products'][$v['supplier_id']][$v['sku']];
        ?>
        <tr>
            <td><?php echo $product['supplier_name'];?></td>
            <td><?php echo $v['sku']; ?></td>
            <td><?php echo $product['productname']; ?></td>
            <td><?php echo $product['nuit']; ?></td>
            <td><?php echo $warehouses[$v['warehouseid']]['name']; ?></td>
            <!--<td><?php echo $v['storage_position']?></td>-->
            <td><?php echo (int)$v['quantity']; ?></td>
            <td><?php echo (int)$v['sales']; ?>
            </td>
        </tr>
        <?php }?>
    </table>
    <?php echo isset($pagination) ? $pagination : ''; ?>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        laydate.render({
            elem: '#date_from'
        });
        laydate.render({
            elem: '#date_to'
        });
        $("#supplier_name").autocomplete({
            autoFocus: true,
            minLength: 0,
            autoFill: true,
            source: '<?php echo URL::base(true)?>purchase/get_supplier',
            select: function (event, ui) {
                $("#supplier_name").val(ui.item.name);
                // $("#supplier_id").val(ui.item.id);
                return false;
            }
        });
    });
    function clear(e){
        var e = e || window.event;
        $("#supplier_id").val('');
        $("#supplier_name").val('');
        $("#supplier_name").attr("readonly", false);
        if(typeof(e) == 'undefined'){
            return ;
        }else{
            e.preventDefault && e.preventDefault();
        }
    }
</script>
